﻿@model VietPremier.Areas.AdminCP.Models.AdminUserManagerModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}

@helper Truncate(string input, int length)
{
    if (input.Length <= length)
    { 
        @Html.Raw(input)
    }
    else
    { 
        @Html.Raw(input.Substring(0, length))<text>...</text>
    }
}

<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        //LoadTable();
        $('#nofSuccess').hide(); // an thong bao
        $('#nofError').hide();
    });

    function alertMsg(msg) {
        $('#nofSuccess').hide();
        $('#nofError').show();
        $('#msgNofError').text(msg);
    }
    //function LoadTable() {
    //    var table = jQuery("#dyntable").dataTable({
    //        "bDestroy": true,
    //        "bProcessing": true,
    //        "sPaginationType": "full_numbers",
    //        "aaSorting": [[0, "desc"]],
    //        "iDisplayLength": 50
    //    });
    //};

    function DeleteRecord(id) {
        var answer = confirm("Are you sure to delete this record?");
        if (answer) {
            var getURL = '@Url.Action("Delete", "AdminUserManager")';
            $.get(getURL, { "id": id }, function (data) {
                if (data == "Ok") {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");
                    window.location.href = '@Url.Action("Index", "AdminUserManager")';
                }
                else {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                    alertMsg("Cannot delete, Please contact to website's technical");
                    //window.location.href = '@Url.Action("Index", "Error", new { errorMsg = "Can not delete!" })';
                }
            });
        }
        else {
            return false;
        }

        return false;
    }

</script>

<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminUserManager")">Quản lý tài khoản</a></li>
        <li class="current"><a href="@Url.Action("Insert", "AdminUserManager")">Thêm tài khoản mới</a></li>
    </ul>
    <!--maintabmenu-->



    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->


    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->


    <div class="contenttitle radiusbottom0">
        <h2 class="table"><span>Danh sách tài khoản</span></h2>
    </div>
    <!--contenttitle-->

    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
        <colgroup>
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
        </colgroup>
        <thead>
            <tr>
                <th class="head1"></th>                
                <th class="head1">Tên</th>
                <th class="head0">Loại</th>
                <th class="head1">Nhiệm vụ</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th class="head1"></th>                
                <th class="head1">Tên</th>
                <th class="head0">Loại</th>
                <th class="head1">Nhiệm vụ</th>
            </tr>
        </tfoot>
        <tbody>

            @{
                int i = 1;
                foreach (var item in Model.listAdminUserManager)
                {
                    
                <tr class="gradeX">
                    <td class="center">@i</td>                    
                    <td>@Html.DisplayFor(modelitem => item.username)</td>
                    <td>@Html.DisplayFor(modelitem => item.type)</td>
                    <td class="center">
                        <a class="" href="@Url.Action("Edit", new { idUserManager = @item.ID })">Sửa</a>
                        &nbsp; 
                        <a class="" href="#" onclick="DeleteRecord(@item.ID)" >Xóa</a>    
                    </td>
                </tr>
                    i++;
                }
            }
        </tbody>
    </table>




</div>
<!--maincontentinner-->
